package com.qupai.controller.admin;

import com.qupai.dto.PtRegistrationAddDTO;
import com.qupai.dto.PtRegistrationDeleteDTO;
import com.qupai.entity.User;
import com.qupai.result.Result;
import com.qupai.service.PtRegistrationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminPtRegistrationController")
@RequestMapping("/admin/ptregister")
@Slf4j
@Tag(name = "普通-活动报名表浏览接口")
@RequiredArgsConstructor
public class PtRegistrationController {

    private final PtRegistrationService registrationService;

    @GetMapping("/{id}")
    @Operation(summary = "根据活动id查询活动报名人员名单")
    public Result<List<User>> getRegistrationById(@PathVariable Long id){
        log.info("根据活动id查询报名名单：{}",id);
        List<User> signUpUsers = registrationService.getRegistrationsByActivityId(id);
        return Result.success(signUpUsers);
    }

    @DeleteMapping
    @Operation(summary = "根据活动id和用户id删除报名人员")
    public Result<String> deleteById(@RequestBody PtRegistrationDeleteDTO registrationDeleteDTO){
        log.info("根据活动id:{},删除用户ids：{}",registrationDeleteDTO.getActivityId(),registrationDeleteDTO.getUserIds());
        registrationService.deleteUser(registrationDeleteDTO);
        return Result.success();
    }

    @PostMapping
    @Operation(summary = "根据学号添加报名人员")
    public Result<String> addByUserCode(@RequestBody PtRegistrationAddDTO registrationAddDTO){
        log.info("根据学号添加报名人员，活动：{},学号：{}",registrationAddDTO.getActivity(),registrationAddDTO.getStudentId());
        registrationService.addByStudentId(registrationAddDTO);
        return Result.success();
    }
}
